package com.mec.ServerCluser.core;

import com.mec.ServerCluser.Interface.IUserClientBanlanceChoose;

import java.util.List;
import java.util.Map;

public class UserClientBanlanceChooseAdapter implements IUserClientBanlanceChoose {
    @Override
    public AppServerDefination banlanceChooseServer
            (String serviceName, Map<String, List<AppServerDefination>> serviceMap) {
        if(serviceMap == null) {
            return null;
        }
        List<AppServerDefination> serverList = serviceMap.get(serviceName);
        AppServerDefination curFastServer;
        AppServerDefination nextServer;
        curFastServer = serverList.get(0);
        for(int index = 0; index < serverList.size(); index++) {
            nextServer = serverList.get(index+1);
            curFastServer = ((curFastServer.getResponseTime() <= nextServer.getResponseTime()))
            ? curFastServer : nextServer;
        }

        return curFastServer;
    }
}
